﻿@model IEnumerable<RepertorySystem.Models.AccountList>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" />
@Scripts.Render("~/bundles/jquery")
@{
    ViewBag.Title = "Index";
}
@{
    //获取端口
    IServiceProvider provider = (IServiceProvider)HttpContext.Current;
    HttpWorkerRequest request = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
    var port = HttpContext.Current.Request.Url.Port;
}
<h2>账目详情 <span class="glyphicon glyphicon-usd" style="color: rgb(200, 153, 107);"></span></h2>
@*<p>
        @Html.ActionLink("Create New", "Create")
    </p>*@
<div class="col-lg-3 divfloat">
    <div class="input-group">
        <input id="searchInput" type="text" class="form-control" placeholder="输入书名" />
        <span class="input-group-btn">
            <input id="searchButton" class="btn btn-default" type="button" value="搜索" />
        </span>
    </div><!-- /input-group -->
</div>

@*<input id="searchInput" placeholder="输入书名"/><input id="searchButton" type="button" value="搜索" /><br /><br />*@
<div id="a_Div"></div>
<script type="text/javascript">
    $("#searchButton").click(function(){
        var searchContent = $("#searchInput").val();

        if(searchContent == "" ){
            alert("请输入搜索内容");
        }else{
            window.location.href ="http://localhost:"+@port+"/AccountLists/FindOne?book_Name="+searchContent;
        }
    });

</script>

<input id="count" type="button" value="统计" class="btn btn-default" style="display:inline-block;"/>

<script type="text/javascript">
    $("#count").click(function(){
        window.location.href ="http://localhost:"+@port+"/AccountLists/AccountCount";
       
    });
</script>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Time)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Category)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Book_Id)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Book_Number)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Price)
        </th>
        <th>
            操作
        </th>
    </tr>
    @if (ViewBag.content == null) {
        <tr>未查找到内容！</tr>
    } else {
        foreach (var item in ViewBag.content) {

            <tr>
                <td>
                    @item.Time.ToString("yyyy-MM-dd")
                </td>
                <td class="@item.Category-category">
                    <script type="text/javascript">
                    $(".0-category").text("出库");
                    $(".1-category").text("入库");
                    </script>
                </td>
                <td class="@item.Book_Id">

                    @if (@item.Book_Id != null) {

                        <script type="text/javascript">
                        var bookId = @item.Book_Id
                        $.ajax({
                            url: "http://localhost:"+@port+"/api/Books/"+bookId,
                            type:"get",
                            success: function (result) {
                                $(".@item.Book_Id").text(result.Name);
                            },
                            error: function (msg) {
                                console.log(msg);
                            }

                        });

                        </script>
                    }
                </td>

                <td>
                    @item.Book_Number
                </td>
                <td>
                    @item.Price
                </td>
                <td>
                    @*@Html.ActionLink("修改", "Edit", new { id=item.ID }) |*@
                    @*@Html.ActionLink("Details", "Details", new { id=item.ID }) |*@
                    <span class="glyphicon glyphicon-trash" style="color: rgb(200, 153, 107); font-size: 15px;">
                        @Html.ActionLink("删除", "Delete", new { id = item.ID })
                    </span>
                </td>
            </tr>
        }
    }
   
</table>
<div id="pagebar">
    <ul class="pagination">
        @for (var i = 0; i < ViewBag.totalPages; i++)
        {

            if (ViewBag.currentPage == (i + 1))
            {
                <li><span class="currentPage">@(i + 1)</span></li>
            }
            else
            {
                //<a class="nextOrPreviousPage" href="javascript:;">@(i + 1)</a>
                var number = i + 1;
                <li>@Html.ActionLink("" + number, "GetNext", new { currentPage = number });</li>
            }
        }
    </ul>
</div>


